// #define print(...)
class Solution {
public:
    vector<vector<int>> threeSum(vector<int>& nums) {
        if(nums.empty()) return {};
        sort(nums.begin(), nums.end());
        print(nums, "\n")
        vector<vector<int>> ans;
        for(auto s=nums.begin(); s!=nums.end(); s++){
            if(nums.begin()<s && *(s-1)==*s) continue;
            auto m = s+1, b = nums.end()-1;
            while(m < b){
                print(*s, ' ', *m, ' ', *b, "\n")
                if(0 < *s+*m+*b){
                    do{ --b; }while(m<b && *(b+1)==*b);
                }else{
                    if(0 == *s+*m+*b)
                        ans.push_back({*s,*m,*b});
                    do{ ++m; }while(m<b && *(m-1)==*m);
                }
                if(s==b) return ans;
            }
        }
        return ans;
    }
};
